#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int cnt = 0;
    int pa = 0;
    for(int pb = 0; pb < n; pb++) {
        if(a[pa] >= b[pb]) cnt++;
        else pa++;
    }
    cout << cnt << endl;
}

int main() {
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}